package com.ygxsk.carhome.ui.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.enumwrap.LeadCarStepStatus;
import com.ygxsk.carhome.response.LeadsFollowStepBean;
import com.ygxsk.carhome.utils.CommUtils;

import java.util.List;

/*
 * @Author:itchenqi175@163.com
 * @Time:2023-07-12  17:46
 * @Description:添加潜在客户详情
 */
public class LeadDetailAdapter extends BaseQuickAdapter<LeadsFollowStepBean, BaseViewHolder> {

    public LeadDetailAdapter(int layoutResId, @Nullable List<LeadsFollowStepBean> data) {
        super(layoutResId, data);

        //是否添加其他点击事件；

    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, LeadsFollowStepBean leadsFollowStepBean) {

        if (leadsFollowStepBean != null) {

            //真实的进度，做判断；
            String status = leadsFollowStepBean.getStatus();
            //跟进状态的标题--是这个状态本身
            String statusName = leadsFollowStepBean.getStatusName();
            //跟进的文本内容--备注信息
            String remark = leadsFollowStepBean.getRemark();
            //跟进人员-人员姓名
            String createCustomerName = leadsFollowStepBean.getCreateCustomerName();
            //跟进时间--添加进度的时间创建
            String createTime = leadsFollowStepBean.getCreateTime();

            //合并findview
            //顶部最终状态图片
            ImageView imageTopCheck = (ImageView) baseViewHolder.getView(R.id.imagetopcheck);
            ImageView imageMiddle = (ImageView) baseViewHolder.getView(R.id.imagemiddle);
            ImageView imageBottomCheck = (ImageView) baseViewHolder.getView(R.id.imagebottomcheck);

            // : 2023-07-12 21:30 暂时设置middle为显示状态
            CommUtils.setViewVisible(imageMiddle);


            //跟进记录的描述
            TextView textViewTitleCustomerRecord = (TextView) baseViewHolder.getView(R.id.textviewtitlecustomerrecord);

            //真实的状态描述
            TextView textViewCheckStageDes = (TextView) baseViewHolder.getView(R.id.textviewcheckstagedes);

            //跟进人
            TextView textViewFollowpPerson = (TextView) baseViewHolder.getView(R.id.textviewfollowperson);
            //跟进时间
            TextView textViewFollowTime = (TextView) baseViewHolder.getView(R.id.textviewfollowtime);

            // : 2023-07-12 19:12  备注信息，没有备注  是要隐藏
            //文本内容
            LinearLayout linearLayoutTextInputInfo = (LinearLayout) baseViewHolder.getView(R.id.linearlayouttextinputinfolead);
            //可能是隐藏的
            TextView textVieweEditInputContent = (TextView) baseViewHolder.getView(R.id.textvieweeditinputcontent);
            //底部的帮助布局，如果是最后一条数据的话 就展开
            TextView textViewInLeadDetailHelpBottom = (TextView) baseViewHolder.getView(R.id.textviewinleaddetailhelpbottom);

            //filldatas

            //LeadCarStepStatus
            //跟进状态：0:待联系;1:初步接洽;2:有意向;3无意向;4成功;5战败;6取消预约
//                    LEAD_STEP_TO_BE_CONTACT("0", "待联系"),
//                    LEAD_STEP_TO_INIT_CONTACT("1", "初步接洽"),
//                    LEAD_STEP_HAS_A_INTENT("2", "有意向"),
//                    LEAD_STEP_HAS_NO_INTENT("3", "无意向"),
//                    LEAD_STEP_SUCCESS("4", "成功"),
//                    LEAD_STEP_FAIL("5", "战败"),
//                    LEAD_STEP_CANCEL_BOOKING("6", "取消预约");


            int indexPosition = getItemPosition(leadsFollowStepBean);

            if (getData().size() > 1) {

                if (indexPosition == 0) {
                    //顶部标题展示
                    textViewTitleCustomerRecord.setVisibility(View.VISIBLE);
                    //如果是第0条，那么占位，但是不隐藏；
                    imageTopCheck.setVisibility(View.INVISIBLE);
                } else {
                    imageTopCheck.setVisibility(View.VISIBLE);
                    //顶部标题隐藏
                    textViewTitleCustomerRecord.setVisibility(View.GONE);
                }

                //如果是[最后一条数据]，那么应该隐藏中间的内容.
                if (indexPosition == getData().size() - 1) {
                    CommUtils.setViewGone(imageBottomCheck);
                    CommUtils.setViewVisible(textViewInLeadDetailHelpBottom);
                } else {
                    CommUtils.setViewVisible(imageBottomCheck);
                    CommUtils.setViewGone(textViewInLeadDetailHelpBottom);
                }

            } else if (getData().size() == 1) {
                textViewTitleCustomerRecord.setVisibility(View.VISIBLE);
                imageTopCheck.setVisibility(View.VISIBLE);
                CommUtils.setViewVisible(textViewInLeadDetailHelpBottom);
            }

            //人员的跟进进度，如果是4，标志成功；那么就展示红色图标
            if (TextUtils.equals(status, LeadCarStepStatus.LEAD_STEP_SUCCESS.getIndex())) {
                imageMiddle.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.ic_marker_active));
            } else {
                imageMiddle.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.ic_marker_inactive));
            }

            //状态步进
            CommUtils.setText(textViewCheckStageDes, statusName);

            //跟进人
            CommUtils.setText(textViewFollowpPerson, createCustomerName);

            //跟进时间
            CommUtils.setText(textViewFollowTime, createTime);

            //备注的文本内容,如果没有备注，那么备注的文本框隐藏
            //remark="";
            if (!TextUtils.isEmpty(remark)) {
                CommUtils.setViewVisible(linearLayoutTextInputInfo);
                CommUtils.setText(textVieweEditInputContent, remark);
            } else {
                CommUtils.setViewGone(linearLayoutTextInputInfo);
                CommUtils.setText(textVieweEditInputContent, "");
            }

        }

    }
}
